﻿using SD.Infrastructure.EntityBase;
using SlamDunk.ValueObjects.Enums;
using System;
using System.Text;

namespace SlamDunk.MES.Domain.Entities.StockContext
{
    /// <summary>
    /// 库存单据类
    /// </summary>
    public class StockOrderClass : AggregateRootEntity
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected StockOrderClass() { }
        #endregion

        #region 01.创建库存单据类构造器
        /// <summary>
        /// 创建库存单据类构造器
        /// </summary>
        /// <param name="classNo">库存单据类编号</param>
        /// <param name="className">库存单据类名称</param>
        /// <param name="directionType">出入库方向类型</param>
        /// <param name="generateBarcode">是否生成条码</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        public StockOrderClass(string classNo, string className, StockDirectionType directionType, bool? generateBarcode, Guid? facilityId, string description)
            : this()
        {
            #region # 验证

            if (directionType == StockDirectionType.Input && !generateBarcode.HasValue)
            {
                throw new ArgumentNullException(nameof(generateBarcode), "出入库方向类型为入库时，是否生成条码属性必须赋值！");
            }

            #endregion

            base.Number = classNo;
            base.Name = className;
            this.DirectionType = directionType;
            this.GenerateBarcode = generateBarcode;
            this.FacilityId = facilityId;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 出/入库方向类型 —— StockDirectionType DirectionType
        /// <summary>
        /// 出/入库方向类型
        /// </summary>
        public StockDirectionType DirectionType { get; private set; }
        #endregion

        #region 是否生成条码 —— bool? GenerateBarcode
        /// <summary>
        /// 是否生成条码
        /// </summary>
        public bool? GenerateBarcode { get; private set; }
        #endregion

        #region 工厂模型Id —— Guid? FacilityId
        /// <summary>
        /// 工厂模型Id
        /// </summary>
        public Guid? FacilityId { get; private set; }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        #endregion

        #endregion

        #region # 方法

        #region 修改库存单据类 —— void UpdateInfo(string classNo...
        /// <summary>
        /// 修改库存单据类
        /// </summary>
        /// <param name="classNo">库存单据类编号</param>
        /// <param name="className">库存单据类名称</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        public void UpdateInfo(string classNo, string className, Guid? facilityId, string description)
        {
            base.Number = classNo;
            base.Name = className;
            this.FacilityId = facilityId;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(base.Number);
            builder.Append(base.Name);
            builder.Append(this.Description);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
